package com.leyou.common.advices;

import com.leyou.common.exceptions.LyException;
import com.leyou.common.vo.ExceptionResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

/**
 * @package com.leyou.item.advices
 * @description: 动态异常处理
 * @author: 许超越
 * @date 2019/6/22 16:36
 * @version: V1.0
 */
@ControllerAdvice
@Slf4j
public class BasicExceptionAdvice {

    @ExceptionHandler(RuntimeException.class)
    public ResponseEntity<ExceptionResult> handleException(LyException e) {
        //暂定状态码返回为400
        return ResponseEntity.status(e.getStatus()).body(new ExceptionResult(e));
    }
}
